<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;

use app\common\model\UserAccount;
use app\common\model\UserAccountLog;
use app\common\model\UserPayType;
use think\Db;

/**
 * 逻辑
 */
class Memberpay extends AdminBase
{



    /**
     * 获取
     */
    public function getPaylist($data = [], $field = 'm.*,b.nickname as leader_nickname')
    {


        $where['user_id'] =$data['user_id'];
        $where['type']=3;
        $list['bank']=$this->modelUserPayType->getInfo($where);
        $where['type']=2;
        $list['wechat']=$this->modelUserPayType->getInfo($where);
        $where['type']=1;
        $list['alipay']=$this->modelUserPayType->getInfo($where);
//        $where['type']=4;
//        $list['eth']=$this->modelUserPayType->getInfo($where);


        return $list;

    }

    /**
     * 获取
     */
    public function memberEdit($data)
    {
//       dd($data);
        Db::startTrans();

        try{
            if($data['type_text']=='支付宝'){

                $alipay=$data['alipay'];
//               dd($data['alipay_cover_id']);
                if(!$alipay['true_name']){
                    return [RESULT_ERROR, '支付宝真实姓名不能为空'];
                }
                if(!$alipay['bank_card']){
                    return [RESULT_ERROR, '支付宝账号不能为空'];
                }
//                if(!$alipay['ali_name']){
//                    return [RESULT_ERROR, '支付宝名称不能为空'];
//                }
                if(!$data['alipay_cover_id']){
                    return [RESULT_ERROR, '支付宝收款二维码不能为空'];
                }
                $alipay['cover_id']=$data['alipay_cover_id'];
                if(!$alipay['id']){
                    unset($alipay['id']);
                    $alipay['type']=1;
                    $alipay['user_id']=$data['user_id'];

                    UserPayType::create($alipay);
                }else{
                    UserPayType::update($alipay);
                }
            }

            if($data['type_text']=='银行卡'){

                $bank=$data['bank'];
                if(!$bank['true_name']){
                    return [RESULT_ERROR, '开户姓名不能为空'];
                }
                if(!$bank['opening_bank']){
                    return [RESULT_ERROR, '开户银行不能为空'];
                }
                if(!$bank['bank_address']){
                    return [RESULT_ERROR, '银行地址不能为空'];
                }
                if(!$bank['bank_card']){
                    return [RESULT_ERROR, '银行卡号不能为空'];
                }

                if(!$bank['id']){
                    unset($bank['id']);
                    $bank['type']=3;
                    $bank['user_id']=$data['user_id'];

                    UserPayType::create($bank);
                }else{
                    UserPayType::update($bank);
                }

            }


            if($data['type_text']=='微信'){

                $wechat=$data['wechat'];
                if(!$wechat['true_name']){
                    return [RESULT_ERROR, '微信真实姓名不能为空'];
                }
                if(!$wechat['bank_card']){
                    return [RESULT_ERROR, '微信账号不能为空'];
                }
//                if(!$wechat['wechat_name']){
//                    return [RESULT_ERROR, '微信昵称不能为空'];
//                }
                if(!$data['wechat_cover_id']){
                    return [RESULT_ERROR, '微信收款二维码不能为空'];
                }
                $wechat['cover_id']=$data['wechat_cover_id'];
                if(!$wechat['id']){
                    unset($wechat['id']);
                    $wechat['type']=2;
                    $wechat['user_id']=$data['user_id'];

                    UserPayType::create($wechat);
                }else{
                    UserPayType::update($wechat);
                }

            }



//            if($data['eth']){
//
//                $eth=$data['eth'];
//                if(!$eth['currency_address']){
//                    return [RESULT_ERROR, '微信真实姓名不能为空'];
//                }
//                if(!$eth['currency_id']){
//                    return [RESULT_ERROR, '微信账号不能为空'];
//                }
//
//                if(!$data['eth_cover_id']){
//                    return [RESULT_ERROR, '数字货币收款二维码不能为空'];
//                }
//                $eth['cover_id']=$data['eth_cover_id'];
//                if(!$eth['id']){
//                    unset($eth['id']);
//                    $eth['type']=4;
//                    $eth['user_id']=$data['user_id'];
//                    UserPayType::create($eth);
//                }else{
//                    UserPayType::update($eth);
//                }
//
//            }


            Db::commit();
        }catch (\Exception $e){
            Db::rollback();
            return [RESULT_ERROR, $e->getMessage()];
        }



        $url = url('userPay/user_pay',['user_id'=>$data['user_id']]);
        return [RESULT_SUCCESS, '修改成功', $url];

    }





}
